import React, { Component } from 'react'
import routerConfig from './routerConfig'
import { NavLink } from 'react-router-dom'
import {Menu} from 'antd'
export class RouterLink extends Component {
    constructor(props) {
      super(props)
    
      this.state = {
         keyPath:[]
      }
    }
    componentDidMount(){
        let keyPath=localStorage.getItem('keyPath')?
        JSON.parse(localStorage.getItem('keyPath')):['/dash/fenxi','0']
        this.setState({
            keyPath:keyPath
        })
    }
    render() {
        let {keyPath}=this.state
        return (
            <div>
                <Menu mode='inline' 
                openKeys={[keyPath[1]]}
                selectedKeys={[keyPath[0]]}
                onClick={(obj)=>{
                    // console.log(obj);
                    const {keyPath}=obj
                    localStorage.setItem('keyPath',JSON.stringify(keyPath))
                    this.setState({
                        keyPath
                    })
                }}
                onOpenChange={(e)=>{
                    keyPath[1]=e[1]
                    this.setState({
                        keyPath
                    })
                }}
                >
                    {routerConfig.length?routerConfig.map((item,index)=>{
                        return item.show?<Menu.SubMenu key={index} title={item.title}>
                        {item.children?item.children.map((v,i)=>{
                            return <Menu.Item key={v.path}>
                                <NavLink to={v.path}>{v.title}</NavLink>
                            </Menu.Item>
                        }):'暂无数据'}
                    </Menu.SubMenu>:null
                    }):'暂无数据'}
                </Menu>
            </div>
        )
    }
}

export default RouterLink